<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>listener.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_events_listener.js.html">listener.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2005 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Listener object.
<a name="line17"></a> * @see ../demos/events.html
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.events.Listener&#39;);
<a name="line21"></a>
<a name="line22"></a>goog.require(&#39;goog.events.ListenableKey&#39;);
<a name="line23"></a>
<a name="line24"></a>
<a name="line25"></a>
<a name="line26"></a>/**
<a name="line27"></a> * Simple class that stores information about a listener
<a name="line28"></a> * @param {!Function} listener Callback function.
<a name="line29"></a> * @param {Function} proxy Wrapper for the listener that patches the event.
<a name="line30"></a> * @param {EventTarget|goog.events.Listenable} src Source object for
<a name="line31"></a> *     the event.
<a name="line32"></a> * @param {string} type Event type.
<a name="line33"></a> * @param {boolean} capture Whether in capture or bubble phase.
<a name="line34"></a> * @param {Object=} opt_handler Object in whose context to execute the callback.
<a name="line35"></a> * @implements {goog.events.ListenableKey}
<a name="line36"></a> * @constructor
<a name="line37"></a> */
<a name="line38"></a>goog.events.Listener = function(
<a name="line39"></a>    listener, proxy, src, type, capture, opt_handler) {
<a name="line40"></a>  if (goog.events.Listener.ENABLE_MONITORING) {
<a name="line41"></a>    this.creationStack = new Error().stack;
<a name="line42"></a>  }
<a name="line43"></a>
<a name="line44"></a>  /**
<a name="line45"></a>   * Callback function.
<a name="line46"></a>   * @type {Function}
<a name="line47"></a>   */
<a name="line48"></a>  this.listener = listener;
<a name="line49"></a>
<a name="line50"></a>  /**
<a name="line51"></a>   * A wrapper over the original listener. This is used solely to
<a name="line52"></a>   * handle native browser events (it is used to simulate the capture
<a name="line53"></a>   * phase and to patch the event object).
<a name="line54"></a>   * @type {Function}
<a name="line55"></a>   */
<a name="line56"></a>  this.proxy = proxy;
<a name="line57"></a>
<a name="line58"></a>  /**
<a name="line59"></a>   * Object or node that callback is listening to
<a name="line60"></a>   * @type {EventTarget|goog.events.Listenable}
<a name="line61"></a>   */
<a name="line62"></a>  this.src = src;
<a name="line63"></a>
<a name="line64"></a>  /**
<a name="line65"></a>   * The event type.
<a name="line66"></a>   * @const {string}
<a name="line67"></a>   */
<a name="line68"></a>  this.type = type;
<a name="line69"></a>
<a name="line70"></a>  /**
<a name="line71"></a>   * Whether the listener is being called in the capture or bubble phase
<a name="line72"></a>   * @const {boolean}
<a name="line73"></a>   */
<a name="line74"></a>  this.capture = !!capture;
<a name="line75"></a>
<a name="line76"></a>  /**
<a name="line77"></a>   * Optional object whose context to execute the listener in
<a name="line78"></a>   * @type {Object|undefined}
<a name="line79"></a>   */
<a name="line80"></a>  this.handler = opt_handler;
<a name="line81"></a>
<a name="line82"></a>  /**
<a name="line83"></a>   * The key of the listener.
<a name="line84"></a>   * @const {number}
<a name="line85"></a>   * @override
<a name="line86"></a>   */
<a name="line87"></a>  this.key = goog.events.ListenableKey.reserveKey();
<a name="line88"></a>
<a name="line89"></a>  /**
<a name="line90"></a>   * Whether to remove the listener after it has been called.
<a name="line91"></a>   * @type {boolean}
<a name="line92"></a>   */
<a name="line93"></a>  this.callOnce = false;
<a name="line94"></a>
<a name="line95"></a>  /**
<a name="line96"></a>   * Whether the listener has been removed.
<a name="line97"></a>   * @type {boolean}
<a name="line98"></a>   */
<a name="line99"></a>  this.removed = false;
<a name="line100"></a>};
<a name="line101"></a>
<a name="line102"></a>
<a name="line103"></a>/**
<a name="line104"></a> * @define {boolean} Whether to enable the monitoring of the
<a name="line105"></a> *     goog.events.Listener instances. Switching on the monitoring is only
<a name="line106"></a> *     recommended for debugging because it has a significant impact on
<a name="line107"></a> *     performance and memory usage. If switched off, the monitoring code
<a name="line108"></a> *     compiles down to 0 bytes.
<a name="line109"></a> */
<a name="line110"></a>goog.define(&#39;goog.events.Listener.ENABLE_MONITORING&#39;, false);
<a name="line111"></a>
<a name="line112"></a>
<a name="line113"></a>/**
<a name="line114"></a> * If monitoring the goog.events.Listener instances is enabled, stores the
<a name="line115"></a> * creation stack trace of the Disposable instance.
<a name="line116"></a> * @type {string}
<a name="line117"></a> */
<a name="line118"></a>goog.events.Listener.prototype.creationStack;
<a name="line119"></a>
<a name="line120"></a>
<a name="line121"></a>/**
<a name="line122"></a> * Marks this listener as removed. This also remove references held by
<a name="line123"></a> * this listener object (such as listener and event source).
<a name="line124"></a> */
<a name="line125"></a>goog.events.Listener.prototype.markAsRemoved = function() {
<a name="line126"></a>  this.removed = true;
<a name="line127"></a>  this.listener = null;
<a name="line128"></a>  this.proxy = null;
<a name="line129"></a>  this.src = null;
<a name="line130"></a>  this.handler = null;
<a name="line131"></a>};
</pre>


</body>
</html>
